package com.hos.check.util;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;
import org.springframework.core.convert.converter.Converter;

public class SpringMvcDateConverter implements  Converter<String, Date>{

	public Date convert(String dateString) {
		
		String[] pattern = new String[]{"yyyy-MM","yyyyMM","yyyy/MM",   
                "yyyyMMdd","yyyy-MM-dd","yyyy/MM/dd",   
                "yyyyMMddHHmmss",   
                            "yyyy-MM-dd HH:mm:ss",   
                            "yyyy/MM/dd HH:mm:ss"};  
		
		try {
			return DateUtils.parseDate(dateString,pattern);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static void main(String[] args) {
		
		String[] pattern = new String[]{"yyyy-MM","yyyyMM","yyyy/MM",   
                "yyyyMMdd","yyyy-MM-dd","yyyy/MM/dd",   
                "yyyyMMddHHmmss",   
                            "yyyy-MM-dd HH:mm:ss",   
                            "yyyy/MM/dd HH:mm:ss"};  
		
		try {
			Date dt= DateUtils.parseDate("2012-12-12",pattern);
			System.out.println(dt.toString());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		//	return null;
		}
		
	}

}
